# Maintainer: Daurnimator <quae@daurnimator.com>

pkgname=('lua-http' 'lua53-http' 'lua52-http' 'lua51-http')
pkgver=0.4
pkgrel=1
arch=('any')
pkgdesc='HTTP Library for Lua'
url='https://github.com/daurnimator/lua-http'
license=('MIT')
makedepends=('luarocks'
             'lua51' 'lua52' 'lua53' 'lua' # https://github.com/luarocks/luarocks/issues/1275
             'pandoc')
source=("$pkgname-$pkgver.tar.gz::https://github.com/daurnimator/lua-http/archive/v$pkgver.tar.gz")
sha256sums=('d2e3cb9bc04cab70ac4f19351bc74b0dcd8b16cfc2563aa77256eb3a43b3b9e0')

build() {
    cd "lua-http-$pkgver"

    for v in 5.1 5.2 5.3 5.4; do
        mkdir -p "$v/"
        luarocks make --pack-binary-rock --lua-version="$v" --deps-mode=none http-"$pkgver"-0.rockspec
        mv http-"$pkgver"-0.*.rock "$v/"
    done

	make -C doc lua-http.3
}

package_lua-http() {
	pkgdesc="$pkgdesc 5.4"
	depends=('lua-cqueues'
	         'lua-luaossl'
	         'lua-basexx'
	         'lua-binaryheap'
	         'lua-lpeg'
	         'lua-lpeg-patterns'
	         'lua-fifo')
	optdepends=('lua-zlib: gzip compression'
	            'lua-psl: public suffix list checking')

	cd "lua-http-$pkgver"
    luarocks install --lua-version=5.4 --tree="$pkgdir/usr/" --deps-mode=none --no-manifest 5.4/*.rock
	install -Dm644 LICENSE.md "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
	install -Dm644 doc/lua-http.3 -t "$pkgdir/usr/share/man/man3/"
}

package_lua53-http() {
    pkgdesc="$pkgdesc 5.3"
    depends=('lua53-cqueues'
             'lua53-luaossl'
             'lua53-basexx'
             'lua53-binaryheap'
             'lua53-lpeg'
             'lua53-lpeg-patterns'
             'lua53-fifo')
    optdepends=('lua53-zlib: gzip compression'
                'lua53-psl: public suffix list checking')

    cd "lua-http-$pkgver"
    luarocks install --lua-version=5.3 --tree="$pkgdir/usr/" --deps-mode=none --no-manifest 5.3/*.rock
    install -Dm644 LICENSE.md "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

package_lua52-http() {
	pkgdesc="$pkgdesc 5.2"
	depends=('lua52-compat53'
	         'lua52-cqueues'
	         'lua52-luaossl'
	         'lua52-basexx'
	         'lua52-binaryheap'
	         'lua52-lpeg'
	         'lua52-lpeg-patterns'
	         'lua52-fifo')
	optdepends=('lua52-zlib: gzip compression'
	            'lua52-psl: public suffix list checking')

	cd "lua-http-$pkgver"
    luarocks install --lua-version=5.2 --tree="$pkgdir/usr/" --deps-mode=none --no-manifest 5.2/*.rock
	install -Dm644 LICENSE.md "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

package_lua51-http() {
    pkgdesc="$pkgdesc 5.1"
    depends=('lua51-compat53'
             'lua51-bitop'
             'lua51-cqueues'
             'lua51-luaossl'
             'lua51-basexx'
             'lua51-binaryheap'
             'lua51-lpeg'
             'lua51-lpeg-patterns'
             'lua51-fifo')
    optdepends=('lua51-zlib: gzip compression'
                'lua51-psl: public suffix list checking')

    cd "lua-http-$pkgver"
    luarocks install --lua-version=5.1 --tree="$pkgdir/usr/" --deps-mode=none --no-manifest 5.1/*.rock
    install -Dm644 LICENSE.md "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
